package com.minimalist.lindi.mapper;

import com.minimalist.common.entity.lindi.po.LindiLaws;
import com.minimalist.common.entity.lindi.vo.laws.LindiLawsQueryVO;
import com.minimalist.common.entity.lindi.vo.laws.LindiLawsVO;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;

/**
 * 林地指标交易平台_政策法规表 映射层。
 *
 * @author 11987
 * @since 2025-06-12
 */
public interface LindiLawsMapper extends BaseMapper<LindiLaws>{

    /**
     * 根据政策法规ID查询政策法规
     *
     * @param lawsId 政策法规ID
     * @return 政策法规
     */
    default LindiLaws selectLawsByLawsId(Long lawsId){
        return selectOneByQuery(QueryWrapper.create()
                .eq(LindiLaws::getLawsId, lawsId));
    }

    /**
     * 根据政策法规ID删除政策法规
     *
     * @param lawsId 政策法规ID
     */
    default void deleteLawsByLawsId(Long lawsId){
        deleteByQuery(QueryWrapper.create().eq(LindiLaws::getLawsId, lawsId));
    }

    /**
     * 根据政策法规ID更新政策法规
     *
     * @param newLaws 政策法规
     */
    default void updateLawsByLawsId(LindiLaws newLaws){
        updateByQuery(newLaws, QueryWrapper.create()
                .eq(LindiLaws::getLawsId, newLaws.getLawsId()));
    }

    /**
     * 分页查询政策法规列表
     *
     * @param queryVO 政策法规查询条件
     * @return 政策法规分页列表
     */
    default Page<LindiLaws> selectPageLawsList(LindiLawsQueryVO queryVO){
        return paginate(queryVO.getPageNum(), queryVO.getPageSize(),
                QueryWrapper.create()
                        .select(LindiLaws::getId
                                , LindiLaws::getLawsId
                                , LindiLaws::getLawsTitle
                                , LindiLaws::getLawsFileId
                                , LindiLaws::getPublishTime
                                , LindiLaws::getStatus
                                , LindiLaws::getCreateId
                                , LindiLaws::getUpdateId
                                , LindiLaws::getCreateTime
                                , LindiLaws::getUpdateTime)
                        .eq(LindiLaws::getStatus, queryVO.getStatus())
                        .like(LindiLaws::getLawsTitle, queryVO.getLawsTitle())
                        .orderBy(LindiLaws::getCreateTime, false));
    }

    /**
     * 前台网站分页查询政策法规列表
     *
     * @param queryVO 政策法规查询条件
     * @return 政策法规分页列表
     */
    default Page<LindiLawsVO> selectWebsiteLawsList(LindiLawsQueryVO queryVO){
        return paginateAs(queryVO.getPageNum(), queryVO.getPageSize(),
                QueryWrapper.create()
                        .select(LindiLaws::getId
                                , LindiLaws::getLawsId
                                , LindiLaws::getLawsTitle
                                , LindiLaws::getLawsFileId
                                , LindiLaws::getPublishTime
                                , LindiLaws::getStatus
                                , LindiLaws::getCreateTime
                                , LindiLaws::getUpdateTime)
                        .eq(LindiLaws::getStatus, queryVO.getStatus())
                        .like(LindiLaws::getLawsTitle, queryVO.getLawsTitle())
                        .orderBy(LindiLaws::getPublishTime, false), LindiLawsVO.class);
    }

    /**
     * 前台网站根据政策法规ID查询政策法规详情
     *
     * @param lawsId 政策法规ID
     * @return 政策法规详情
     */
    default LindiLaws selectWebsiteLawsDetail(Long lawsId){
        return selectOneByQuery(QueryWrapper.create()
                .eq(LindiLaws::getLawsId, lawsId)
                .eq(LindiLaws::getStatus, 1));
    }
}
